package com.wao.cms.service;

import com.wao.cms.domain.TemplateProperty;
import com.wao.cms.repository.TemplatePropertyRepository;
import com.wao.cms.service.dto.TemplatePropertyDTO;
import com.wao.cms.service.mapper.TemplatePropertyMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing TemplateProperty.
 */
@Service
@Transactional
public class TemplatePropertyService {

    private final Logger log = LoggerFactory.getLogger(TemplatePropertyService.class);

    private final TemplatePropertyRepository templatePropertyRepository;

    private final TemplatePropertyMapper templatePropertyMapper;

    public TemplatePropertyService(TemplatePropertyRepository templatePropertyRepository, TemplatePropertyMapper templatePropertyMapper) {
        this.templatePropertyRepository = templatePropertyRepository;
        this.templatePropertyMapper = templatePropertyMapper;
    }

    /**
     * Save a templateProperty.
     *
     * @param templatePropertyDTO the entity to save
     * @return the persisted entity
     */
    public TemplatePropertyDTO save(TemplatePropertyDTO templatePropertyDTO) {
        log.debug("Request to save TemplateProperty : {}", templatePropertyDTO);
        TemplateProperty templateProperty = templatePropertyMapper.toEntity(templatePropertyDTO);
        templateProperty = templatePropertyRepository.save(templateProperty);
        return templatePropertyMapper.toDto(templateProperty);
    }

    /**
     *  Get all the templateProperties.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true)
    public Page<TemplatePropertyDTO> findAll(Pageable pageable) {
        log.debug("Request to get all TemplateProperties");
        return templatePropertyRepository.findAll(pageable)
            .map(templatePropertyMapper::toDto);
    }

    /**
     *  Get one templateProperty by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true)
    public TemplatePropertyDTO findOne(Long id) {
        log.debug("Request to get TemplateProperty : {}", id);
        TemplateProperty templateProperty = templatePropertyRepository.findOne(id);
        return templatePropertyMapper.toDto(templateProperty);
    }

    /**
     *  Delete the  templateProperty by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete TemplateProperty : {}", id);
        templatePropertyRepository.delete(id);
    }
}
